/*
 * Copyright (C) 2012 haru Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.harusource.di.delegate.impl;

import java.lang.reflect.Method;

import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.harusource.di.delegate.Delegate;

/**
 * This class implements SeekBar.OnSeekBarChangeListener.</br>
 * It handles following events of SeekBar.</br>
 * </br>
 *  * NOTE : onStartTrackingTouch and onStopTrackingTouch are merged by the framework, these two event are 
 * dispatched to onStartStopTrackingTouch(SeekBar seekBar, boolean isStart) of target object.</br>
 * </br>
 * <code>
 * void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)</br>
 * void onStartTrackingTouch(SeekBar seekBar)</br>
 * void onStopTrackingTouch(SeekBar seekBar)
 * </code>
 * </br>
 * </br>
 * @see android.widget.SeekBar.OnSeekBarChangeListener#onProgressChanged(android.widget.SeekBar, int, boolean)
 * @see android.widget.SeekBar.OnSeekBarChangeListener#onStartTrackingTouch(android.widget.SeekBar)
 * @see android.widget.SeekBar.OnSeekBarChangeListener#onStopTrackingTouch(android.widget.SeekBar)
 * 
 * @author Hiroki Oizumi
 */
public class SeekBarOnSeekBarChangeListener extends Delegate implements OnSeekBarChangeListener {
    private static final int EVENTHANDLE_ONPROGRESSCHANGED = 1;

    private static final int EVENTHANDLE_ONSTARTSTOPTRACKINGTOUCH = 2;
    

    @Override
    public void add(Method template, Object target, Method eventhandle, View view) {
        super.add(template, target, eventhandle, view);
        ((SeekBar) view).setOnSeekBarChangeListener(this);
    }

    @EventHandler(EVENTHANDLE_ONPROGRESSCHANGED)
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        Delegate.invoke3(mTarget, mEventHandles, EVENTHANDLE_ONPROGRESSCHANGED, seekBar, progress, fromUser);
    }

    @EventHandler(EVENTHANDLE_ONSTARTSTOPTRACKINGTOUCH)
    public void onStartStopTrackingTouch(SeekBar seekBar, boolean isStart){
        // This is a just definition of event handling for applications.
    }
    
    public void onStartTrackingTouch(SeekBar seekBar) {
        Delegate.invoke2(mTarget, mEventHandles, EVENTHANDLE_ONSTARTSTOPTRACKINGTOUCH, seekBar, true);
    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        Delegate.invoke2(mTarget, mEventHandles, EVENTHANDLE_ONSTARTSTOPTRACKINGTOUCH, seekBar, false);
    }
}
